<template>
<div>
  <!-- 1、表单 新增、修改-->
  <div>
    <a-form :model="user">
<!--      1.账号-->
      <a-form-item
          label="账号"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
        <a-input
            placeholder="请输入账号信息"
            v-model:value="user.username"
            v-decorator="[
              'username',
              {rules: [{ required: true, message: '必须填写账号' }]}
            ]" />
      </a-form-item>
<!--      2.密码-->
      <a-form-item
          label="账号"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
        <a-input-password
            placeholder="请输入密码信息"
            v-model:value="user.password"
            v-decorator="[
              'username',
              {rules: [{ required: true, message: '必须填写密码' }]}
            ]" />
      </a-form-item>
<!--      3.角色-->
      <a-form-item
          label="角色"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
        <a-select v-model:value="user.rid">
          <a-select-option value="1">超级管理员</a-select-option>
          <a-select-option value="2">高层</a-select-option>
          <a-select-option value="3">中层</a-select-option>
          <a-select-option value="4">基层</a-select-option>
        </a-select>
      </a-form-item>
<!--      4.按钮-->
      <a-form-item
          :wrapperCol="{ span: 24 }"
          style="text-align: center"
      >
        <a-button htmlType="button" @click="add" type="primary">新增系统用户</a-button>
      </a-form-item>
    </a-form>
  </div>
</div>
</template>

<script setup>
import {ref,onMounted} from "vue";
import store from "store";
import axios from 'axios'
import {router} from "../router/index.js";
const user = ref({
  username:"user01",
  password:"123456"
})

const add=async ()=>{
  console.log(user.value);
  //Axios 请求接口 调用 新增用户
  const r=await axios({
    url:"/api/sysuser/add",
    method:"post",
    data:user.value,
    headers:{
      access_token: store.get('access_token')
    }
  })
  if(r.data.code==0){
    //跳转列表
    router.push("/study/list");
  }
  console.log(r.data);

}
onMounted(async ()=>{
  console.log("页面加载！")
})
</script>

<style scoped>

</style>
